//
//  HQCustomArgumentViewController.m
//  MobileiOS
//
//  Created by 郝庆松 on 2018/6/19.
//  Copyright © 2018年 PCITC. All rights reserved.
//

#import "HQCustomArgumentViewController.h"

@interface HQCustomArgumentViewController ()

@end

@implementation HQCustomArgumentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"自定义参数";
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    // 获取自定义参数
    [self getCustomParam];
}

/**
 获取自定义参数
 */
-(void)getCustomParam{
    [self showHudText:@""];
    [HQNetWork requetParam:[HQParam get_excu_conf:[UserModelManager userID]] withMethod:[HQMethod get_excu_conf] suc:^(NSDictionary *sucData) {
        [self hiddnHud];
        if([sucData[kStatus]integerValue] == 1){
            NSLog(@"获取到的自定义数据是: %@",sucData);
            if(![sucData[@"data"] isKindOfClass:[NSArray class]]){
                NSDictionary *resultDict = sucData[@"data"];
                // 每米布带钩数
                _bdgsField.text = [NSString stringWithFormat:@"%@",resultDict[@"mmbgs"][@"val"]];
                // 每米布带圈数
                _bdqsField.text = [NSString stringWithFormat:@"%@",resultDict[@"mmbqs"][@"val"]];
                // 竖缝纫边宽
                _sfrbkField.text = [NSString stringWithFormat:@"%@",resultDict[@"sfrbk"][@"val"]];
                // 横缝纫边宽
                _hfrbkField.text = [NSString stringWithFormat:@"%@",resultDict[@"hfrbk"][@"val"]];
                // 底边缝纫宽
                _dbfrkField.text = [NSString stringWithFormat:@"%@",resultDict[@"djbk"][@"val"]];
                // 拼接褶尺寸
                _pjzccField.text = [NSString stringWithFormat:@"%@",resultDict[@"pjzcc"][@"val"]];
                // 核算最小值
                _hszxzField.text = [NSString stringWithFormat:@"%@",resultDict[@"hszxz"][@"val"]];
            }
        }else{
            [self tostView:sucData[kInfo]];
        }
    } fail:^{
        [self hiddnHud];
    }];
}

/**
 保存数据
 
 @param sender 按钮
 */
- (IBAction)saveItem:(id)sender {
    if([self isInputEmpty:_bdgsField.text]){
        [self tostView:@"请输入每米布带钩数"];
        return;
    }
    if([self isInputEmpty:_bdqsField.text]){
        [self tostView:@"请输入每米布带圈数"];
        return;
    }
    if([self isInputEmpty:_sfrbkField.text]){
        [self tostView:@"请输入竖缝纫边宽"];
        return;
    }
    if([self isInputEmpty:_hfrbkField.text]){
        [self tostView:@"请输入横缝纫边宽"];
        return;
    }
    if([self isInputEmpty:_dbfrkField.text]){
        [self tostView:@"请输入底边缝纫宽"];
        return;
    }
    if([self isInputEmpty:_pjzccField.text]){
        [self tostView:@"请输入拼接褶尺寸"];
        return;
    }
    if([self isInputEmpty:_hszxzField.text]){
        [self tostView:@"请输入核算最小值"];
        return;
    }
    [self showHudText:@""];
    [HQNetWork requetParam:[HQParam set_excu_conf:[UserModelManager userID] mmbgs:_bdgsField.text mmbqs:_bdqsField.text sfrbk:_sfrbkField.text hfrbk:_hfrbkField.text djbk:_dbfrkField.text pjzcc:_pjzccField.text hszxz:_hszxzField.text] withMethod:[HQMethod set_excu_conf] suc:^(NSDictionary *sucData) {
        [self hiddnHud];
        if([sucData[kStatus]integerValue] == 1){
            NSLog(@"设置自定义参数结果: %@",sucData);
            [self tostView:@"设置成功"];
            
            [self getCustomParam];
        }else{
            [self tostView:sucData[kInfo]];
        }
    } fail:^{
        [self hiddnHud];
    }];
}

@end
